<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 姚波
  Date: 2019/1/19
  Time: 13:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="layuiadmin/layui/css/layui.css">
    <script src="layuiadmin/layui/layui.js"></script>
    <script src="js/jquery.min.3.1.0.js"></script>
</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'/harvest?uid='+${ids}
            ,toolbar: '#toolbarDemo'
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'harve_Id', title:'id', width:100, fixed: 'left', unresize: true, sort: true}
                ,{field:'harve_Region', title:'所在地区', width:200, edit: 'text'}
                ,{field:'harve_Address', title:'详细地址', width:200, edit: 'text'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                var con=confirm("真的要删除吗");
                if(con) {
                    $.ajax({
                        url: "deles?u_id=" + data.harve_Id,   //请求路径
                        datatype: "json",//返回的格式
                        type: "POST", //什么请求
                        success: function (data) { //请求成功以后
                            var obj = eval('(' + data + ')');
                            layer.msg(obj.message);
                            //延时500ms关闭窗口
                            setTimeout(function () {
                                parent.layer.close(index);
                            }, 500);
                        }
                    });
                }
            } else if(obj.event === 'edit'){
                parent.layer.open({   //打开一个弹出层
                    title: '修改信息',   //弹出层的标题
                    maxmin: true,
                    type: 2,
                    content: 'address?u_id='+data.harve_Id,//要访问的地址
                    area: ['800px', '600px'],
                    end: function () { //表示弹出层关闭的时候的代码块
                        location.reload();
                    }
                });
            }
        });
    });
</script>
</body>
</html>